import java.util.Random;

public class 打乱数组中的数据 {
    public static void main(String[] args) {
        //定义储存变量1~5
        int[] arr = {1, 2, 3, 4, 5};
        //遍历储存数组，从0索引开始打乱数据的顺序
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            //生成一个随机索引
            int randomIndex = r.nextInt(arr.length);
            //将随即索引指向的元素跟i指向的元素进行交换
            int temp = arr[i];
            arr[i] = arr[randomIndex];
            arr[randomIndex] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
